#include <bits/stdc++.h>
using namespace std;
#define int unsigned long long
const int MOD = 998244353;
int f[1005],g[1005];
int a[1005],b[1005];
int trie[3000005][2];
map<int, bool> mp[1005];
map<string, bool> ch;
const int p=131;
vector<int> v[1005];
string s;
int n;
void solve1()
{
    int cnt = 1;
    for (int i = 2; i <= n; i++) if (s[i] == 'A' && s[i-1] == 'B') cnt++;
    cout << cnt << endl;
}
bool check(int l, int r)
{
    if ((r-l+1)%2!=0) return 0;
    for (int i = 2; i <= r; i += 2)
    {
        if ((s[i] == 'A' && s[i-1] == 'B') || (s[i] == 'B' && s[i-1] == 'B') || (s[i] == 'A' && s[i-1] == 'A')) continue;
        else return 0;
    }
    return 1;
}
int tot;
signed main()
{
	freopen("song.cpp","r",stdin);
	freopen("song.out","w",stdout);
    cin >> s;
    n = s.length();
    s = " " + s;
    if (n > 1000)
    {
        solve1();
    }
    else
    {
		v[0].push_back(0);
		//cout << "F1\n";
        for (int i = 1; i <= n; i++)
        {
            if (i == 1)
            {
                v[1].push_back(s[1]); continue;
            }
            else 
            {
                for (auto it:v[i-1])
                {
                    int tmp = it * p + s[i];
                    if (!mp[i][tmp])
                    {
                        v[i].push_back(tmp);
                        mp[i][tmp] = 1;
                    }
                    
                }
            }
            //if (i == 3) cout << ":" << v[3].size() << endl;
            for (int j = i-2; j >= 0; j--)
            {
                if (check(j+1,i))
                {
					//if (i == 3) cout << j << ' ' << "F2\n";
                    for (auto it:v[j])
                    {
                        int tmp = it;
                        if (!mp[i][tmp])
                        {
                            mp[i][tmp] = 1;
                            v[i].push_back(tmp);
                        }
                    }
                }
                if (j == 0) break;
            }//cout << i << '\n';
            for (int j = i-1; j > 0; j--)
            {
				if (check(j,i-1))
				{
					for (auto it:v[j-1])
                    {
                        int tmp = it * p + s[i];
                        if (!mp[i][tmp])
                        {
							mp[i][tmp] = 1;
							v[i].push_back(tmp);
						}
                    }
				}
			}
        }
    }
    int ans = v[n].size();
    if (mp[n][0]) ans--; 
    cout << ans;
    //cout << ":" << v[3].size();
    return 0;
}
